home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8852 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.arch.arithmetic,comp.lang.c,comp.lang.c++
  4. Subject: Re: Access carry flag from C
  5. Date: Mon, 26 Feb 96 23:38:52 GMT
  6. Organization: none
  7. Message-ID: <825377932snz@genesis.demon.co.uk>
  8. References: <Dn1C9z.DGv.0.net@indra.com> <ARTHUR.96Feb20143404@gold.Smallworld.co.uk> <824853272snz@genesis.demon.co.uk> <4gqj0d$d6p@airdmhor.gen.nz>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4gqj0d$d6p@airdmhor.gen.nz>
  15.            gumboot@airdmhor.gen.nz "Simon Hosie" writes:
  16.  
  17. >Lawrence Kirby:
  18. >> It certainly can be done portably although not with the efficiency that
  19. >> a platform-specific solution is likely to give you.
  20. >
  21. >>     int j, k;
  22. >
  23. >>     ...
  24. >
  25. >>     if ((j >= 0) ? (k > INT_MAX-j) : (k < INT_MIN-j))
  26. >                     ^^^^^^^^^^^^^^^   ^^^^^^^^^^^^^^^
  27. >  Won't they both be evaluated?
  28.  
  29. No, given:
  30.  
  31.    (expr1) ? expr2 : (expr3)
  32.  
  33. the (ANSI) C language guarantees that expr1 will be evaluated and followed
  34. by a sequence point. If expr1 evaluates to a value that compares unequal
  35. to zero then expr2 is evaluated, otherwise expr3 is evaluated. Under no
  36. circumstances (except undefined behaviour caused by something else in the
  37. program, where anything can happen) can both expr2 and expr3 be evaluated.
  38.  
  39. You probably noticed that I didn't put parentheses around expr2. Can you
  40. see why they are necessary around expr1 and expr3 but not here? (This does
  41. test understanding of expression parsing quite deeply).
  42.  
  43. -- 
  44. -----------------------------------------
  45. Lawrence Kirby | fred@genesis.demon.co.uk
  46. Wilts, England | 70734.126@compuserve.com
  47. -----------------------------------------
  48.